package com.aiyige.im.model;

import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.constant.MsgStatusEnum;
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.RecentContact;

import java.util.Map;

public class SystemMessageModel implements RecentContact {

    public final static int type_system = 1;//系统消息
    public final static int type_interaction = 2;//互动通知
    public final static int type_order = 3;//订单通知

    private int type;
    private String title;
    private String sysMsgContentValue;
    private int headResId;
    private int sysMsgUnreadCount;
    private long notifyTime;

    private SystemMessageModel(Builder builder) {
        setType(builder.type);
        setTitle(builder.title);
        setSysMsgContentValue(builder.sysMsgContentValue);
        setHeadResId(builder.headResId);
        setSysMsgUnreadCount(builder.sysMsgUnreadCount);
        setNotifyTime(builder.notifyTime);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getSysMsgContentValue() {
        return sysMsgContentValue == null ? "暂无新消息" : sysMsgContentValue;
    }

    public void setSysMsgContentValue(String sysMsgContentValue) {
        this.sysMsgContentValue = sysMsgContentValue == null ? "" : sysMsgContentValue;
    }

    public int getSysMsgUnreadCount() {
        return sysMsgUnreadCount;
    }

    public void setSysMsgUnreadCount(int sysMsgUnreadCount) {
        this.sysMsgUnreadCount = sysMsgUnreadCount;
    }


    @Override
    public String getContactId() {
        return getTitle();
    }

    @Override
    public String getFromAccount() {
        return "FromAccount";
    }

    @Override
    public String getFromNick() {
        return "";
    }

    @Override
    public SessionTypeEnum getSessionType() {
        return SessionTypeEnum.System;
    }

    @Override
    public String getRecentMessageId() {
        return "";
    }

    @Override
    public MsgTypeEnum getMsgType() {
        return MsgTypeEnum.custom;
    }

    @Override
    public MsgStatusEnum getMsgStatus() {
        return MsgStatusEnum.unread;
    }

    @Override
    public void setMsgStatus(MsgStatusEnum msgStatusEnum) {

    }

    @Override
    public int getUnreadCount() {
        return getSysMsgUnreadCount();
    }

    @Override
    public String getContent() {
        return getSysMsgContentValue();
    }

    @Override
    public long getTime() {
        return getNotifyTime();
    }

    @Override
    public MsgAttachment getAttachment() {
        return null;
    }

    @Override
    public void setTag(long l) {

    }

    @Override
    public long getTag() {
        return 0;
    }

    @Override
    public Map<String, Object> getExtension() {
        return null;
    }

    @Override
    public void setExtension(Map<String, Object> map) {

    }

    public String getTitle() {
        return title == null ? "" : title;
    }

    public void setTitle(String title) {
        this.title = title == null ? "" : title;
    }



    public int getHeadResId() {
        return headResId;
    }

    public void setHeadResId(int headResId) {
        this.headResId = headResId;
    }



    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public long getNotifyTime() {
        return notifyTime;
    }

    public void setNotifyTime(long notifyTime) {
        this.notifyTime = notifyTime;
    }

    public static final class Builder {
        private String title;
        private String sysMsgContentValue = "暂无新消息";
        private int headResId;
        private int sysMsgUnreadCount;
        private long notifyTime;
        private int type;

        private Builder() {
        }

        public Builder title(String val) {
            title = val;
            return this;
        }

        public Builder sysMsgContentValue(String val) {
            sysMsgContentValue = val;
            return this;
        }

        public Builder headResId(int val) {
            headResId = val;
            return this;
        }

        public Builder sysMsgUnreadCount(int val) {
            sysMsgUnreadCount = val;
            return this;
        }

        public Builder notifyTime(long val) {
            notifyTime = val;
            return this;
        }

        public SystemMessageModel build() {
            return new SystemMessageModel(this);
        }

        public Builder type(int val) {
            type = val;
            return this;
        }
    }
}
